package com.ruoyi.erp.controller;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.erp.domain.HolidayConfigType;
import com.ruoyi.erp.service.IHolidayConfigTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.HolidayConfig;
import com.ruoyi.erp.service.IHolidayConfigService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 节假日管理Controller
 * 
 * @author sauger
 * @date 2022-03-14
 */
@Controller
@RequestMapping("/erp/holiday")
public class HolidayConfigController extends BaseController
{
    private String prefix = "erp/holiday";

    @Autowired
    private IHolidayConfigService holidayConfigService;
    @Autowired
    private IHolidayConfigTypeService holidayConfigTypeService;

    @RequiresPermissions("erp:holiday:view")
    @GetMapping()
    public String holiday()
    {
        return prefix + "/holiday";
    }

    @RequiresPermissions("erp:holiday:list")
    @GetMapping("/{id}")
    public String holidayWithType(@PathVariable("id") Integer id, ModelMap mmap)
    {
        HolidayConfigType type = holidayConfigTypeService.selectHolidayConfigTypeById(id);
        mmap.put("configType", type);
        return prefix + "/holiday";
    }

    /**
     * 查询节假日管理列表
     */
    @RequiresPermissions("erp:holiday:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HolidayConfig holidayConfig)
    {
        startPage();
        List<HolidayConfig> list = holidayConfigService.selectHolidayConfigList(holidayConfig);
        return getDataTable(list);
    }

    /**
     * 导出节假日管理列表
     */
    @RequiresPermissions("erp:holiday:export")
    @Log(title = "节假日管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HolidayConfig holidayConfig)
    {
        List<HolidayConfig> list = holidayConfigService.selectHolidayConfigList(holidayConfig);
        ExcelUtil<HolidayConfig> util = new ExcelUtil<HolidayConfig>(HolidayConfig.class);
        return util.exportExcel(list, "节假日管理数据");
    }

    /**
     * 新增节假日管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    @GetMapping("/add/{id}")
    public String addWithConfigTypeId(@PathVariable("id") Long id, ModelMap mmap)
    {
        HolidayConfig holidayConfig = holidayConfigService.selectHolidayConfigById(id);
        mmap.put("holidayConfig", holidayConfig);
        return prefix + "/add";
    }

    /**
     * 新增保存节假日管理
     */
    @RequiresPermissions("erp:holiday:add")
    @Log(title = "节假日管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HolidayConfig holidayConfig)
    {
        return toAjax(holidayConfigService.insertHolidayConfig(holidayConfig));
    }

    /**
     * 修改节假日管理
     */
    @RequiresPermissions("erp:holiday:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HolidayConfig holidayConfig = holidayConfigService.selectHolidayConfigById(id);
        mmap.put("holidayConfig", holidayConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存节假日管理
     */
    @RequiresPermissions("erp:holiday:edit")
    @Log(title = "节假日管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HolidayConfig holidayConfig)
    {
        return toAjax(holidayConfigService.updateHolidayConfig(holidayConfig));
    }

    /**
     * 删除节假日管理
     */
    @RequiresPermissions("erp:holiday:remove")
    @Log(title = "节假日管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(holidayConfigService.deleteHolidayConfigByIds(ids));
    }
}
